package routes

import (
	"fiber-layout/app/controllers"
	"fiber-layout/app/middleware"
	"fiber-layout/provider/config"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/logger"
	jwtware "github.com/gofiber/jwt/v3"
)

// Load 路由加载
func Load(app *fiber.App) {

	// 加载请求记录
	app.Use(
		logger.New(
			logger.Config{
				Format:     "${time} - ${ip}:${port} - ${method} ${path} \n body:${body}\n",
				TimeFormat: "2006-01-02 15:04:05.000",
				TimeZone:   "Asia/Shanghai",
			},
		),
	)

	app.Get(
		"/hello", func(c *fiber.Ctx) error {
			return c.SendString("Hello, World 👋!")
		},
	)

	//用户注册
	app.Post("/api/v1/users/register", controllers.UserRegister())
	//登录
	app.Post("/api/v1/users/login", controllers.UserLogin())

	//分组
	j := app.Group("/api/v1")
	j.Use(jwtware.New(jwtware.Config{
		SigningKey: []byte(config.Config.GetString("jwt.secret")),
		ErrorHandler: middleware.ErrorHandler(),
	}))
	//删除用户
	j.Delete("/users/:id", controllers.UserDelete())
	//更改信息
	//j.Put("/api/v1/users/:id", controllers.UserUpdate())
	//用户详情
	//app.Get("/api/v1/users/:id", controllers.UserDetail())
	//用户列表
	//app.Get("/api/v1/users", controllers.UserList())

}
